package edu.hunau.commons;


import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;

/**
 * @author hb
 * @date 2022-11-10 15:03:30
 */
public class MyUtils {

    public  static <T,R> List<R> map(List<T> list, Function<T,R> fun){
        List<R> result=new ArrayList<>();
        for(T t:list){
            result.add(fun.apply(t));
        }
        return  result;
    }


    public static <T> void forEach(List<T> list, Consumer<T> consumer){
        for(T t:list){
            consumer.accept(t);
        }
    }

    public  static <T> List<T> filter(List<T> list, Predicate<T> predicate){
        List<T> result=new ArrayList<>();
        for(T t:list){
            if(predicate.test(t)){
                result.add(t);
            }
        }
        return  result;
    }

}
